#ifndef __SMARTPOINTER_H__
#define __SMARTPOINTER_H__

template <typename T>
class SmartPointer
{
	T* m_pointer;
public:
	SmartPointer(T* p);
	~SmartPointer();
	SmartPointer(const SmartPointer<T>& obj);
	SmartPointer<T>& operator = (const SmartPointer<T>& obj);
	T* operator -> ();
	T& operator * ();
	bool isNull();
	T* get();
};

template <typename T>
SmartPointer<T>::SmartPointer(T* p)
{
	m_pointer = p;
}

template <typename T>
SmartPointer<T>::SmartPointer(const SmartPointer<T>& obj)
{
	m_pointer = obj.m_pointer;
	const_cast<SmartPointer<T>&>(obj).m_pointer = NULL;
}

template <typename T>
SmartPointer<T>& SmartPointer<T>::operator = (const SmartPointer<T>& obj)
{
	if (this != obj)
	{
		delete m_pointer;
		m_pointer = obj.m_pointer;
		const_cast<SmartPointer<T>&>(obj).m_pointer = NULL;
	}
	return *this;
}

template <typename T>
T* SmartPointer<T>::operator -> ()
{
	return m_pointer;
}

template <typename T>
T& SmartPointer<T>::operator * ()
{
	return *m_pointer;
}

template <typename T>
bool SmartPointer<T>::isNull()
{
	return m_pointer == NULL;
}

template <typename T>
T* SmartPointer<T>::get()
{
	return m_pointer;
}

template <typename T>
SmartPointer<T>::~SmartPointer()
{
	delete m_pointer;
}





#endif